# -*- coding: utf-8 -*-
from odoo import models, api, fields, tools
from odoo.exceptions import UserError
import re


class station(models.Model):

    _name = "datcent.station"
    _description = "气象站点"
    _table = "datcent_station"
    _order = "sequence"

    sequence = fields.Integer(string="排序",translate = 0)
    name = fields.Char(string="站点名称",translate = 0)
    code = fields.Char(string="站点编码",translate = 0)
    country_id = fields.Many2one(string="国家",comodel_name = 'res.country',default = lambda self:self.env['res.country'].search([('code','=','CN')]),translate = 0)
    region_id = fields.Many2one(string="省市县区",comodel_name = 'setcent.region',translate = 0)
    address = fields.Char(string="具体地址",translate = 0)
    logitude = fields.Float(string="经度",translate = 0)
    latitude = fields.Float(string="纬度",translate = 0)
    altitude = fields.Float(string="海拨",translate = 0)
    detail_contents = fields.Html(string="详细说明",translate = 0)

    # 控制省、市、县分级选择onchange方法
    @api.onchange('province_id')
    def compute_province_id(self):
        for record in self:
            record.prefecture_id = False
            record.county_id = False

    @api.onchange('prefecture_id')
    def compute_prefecture_id(self):
        for record in self:
            record.county_id = False
